#ifndef PORTFOLIO_WIDGET_HPP
#define PORTFOLIO_WIDGET_HPP

#include "tools/stock_table_delegate.hpp"
#include "trading_system.hpp"
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
#include <QVBoxLayout>
#include <QWidget>

class PortfolioWidget : public QWidget {
  Q_OBJECT

public:
  explicit PortfolioWidget(TradingSystem *tradingSystem,
                           QWidget *parent = nullptr);

public slots:
  void onAccountUpdated();

signals:
  void stockSelected(const QString &stockCode, const QString &stockName,
                     double price);

private:
  void setupUI();
  void setupConnections();
  void refreshPortfolioTable();

private:
  TradingSystem *m_tradingSystem;
  QTableView *m_portfolioTableView;
  QStandardItemModel *m_portfolioModel;
  StockTableDelegate *m_portfolioDelegate;
  QLabel *m_balanceLabel;
  QLabel *m_totalAssetsLabel;
  QPushButton *m_refreshButton;
};

#endif // PORTFOLIO_WIDGET_HPP
